﻿
using Dapper;
using hdb;
using hentity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace hwms {
  
    public  class AreaGroup2LocEngine<CS, CSD> :GkTransaction where CS : AbsCoreStock where CSD : AbsCoreStockDetail,new () {

       public long  paramId = 0;
    

    
        protected override TransRes Execute(IDbConnection conn ,IDbTransaction trans ) {
            CoreTaskParam param = conn.GetById<CoreTaskParam>(paramId ,trans);
            CoreTask ct = conn.GetById<CoreTask>(param.taskId ,trans);
            CoreWhGroup group= conn.GetById<CoreWhGroup>(param.des ,trans);
            if( group == null ) {
                return new TransRes();
            }
            string sql = "select * from Core_Wh_Loc where  Active_Status in (0,2) and  area_id =@areaId  and move_group=@locGroup  order by order_No";
            List<CoreWhLoc> locList = conn.Query<CoreWhLoc>(sql ,group ,trans).ToList();

            CoreWhLoc coreWhLoc = LocConfig.select(locList ,-1);
            if( coreWhLoc == null ) {
                return new TransRes();
            }
            String updateSql = "update Core_Task_Param  set des=@des ,status=@status where id=@id";
            conn.Execute(updateSql ,new {des= ( int ) coreWhLoc.id,status = ( int ) CoreTaskParamStatus.可以接收任务,id=param.id } ,trans);


            ct.des = ( int ) coreWhLoc.id;
            ct.info += "-" + ct.des;
            conn.Execute("update core_task set des=@des,info=@info where id=@id" ,ct ,trans);
       
            CoreUtil.UpdataWhLoc(conn ,trans ,coreWhLoc.id,ct.goodDiff);
            return new TransRes();
        }
       
      
    }
}
